<?php
namespace App\Models;


use Illuminate\Database\Eloquent\SoftDeletes;

class Member extends Model
{
    protected $table = 'users';

    public static function getMemberByTag($inputs)
    {
        $tag = Admin::tag();
        $users = Member::query()->join('course_user_access', 'course_user_access.user_id', 'users.id','left');
        $users = $users->select('users.id','users.username','users.nickname');

        if(isSet($inputs['search']) && $inputs['search']){
            $users = $users->where('username', 'LIKE', '%' . $inputs['search'] . '%');
            $users = $users->orWhere('nickname', 'LIKE', '%' . $inputs['search'] . '%');
        }
        if ($tag == 'visitor')
        {
            $users = $users->where('course_user_access.course_id', 86);
        } else if ($tag == 'guest')
        {
            $users = $users->where('course_user_access.course_id', '!=', 86);
        }
        $users = $users->groupBy('users.id');
        return $users = $users->orderBy('users.id', 'DESC')->paginate();
    }
}
